package com.gitee.magic.converter;

import java.nio.charset.Charset;

import com.gitee.magic.core.converter.AbstractConverterEditor;

/**
 * @author start
 */
public class CharacterConverterEditor extends AbstractConverterEditor<String>  {

	public CharacterConverterEditor(Class<?> prototype) {
		super(prototype);
	}

	@Override
	public void restore(Object value) {
		if (value!=null) {
			setValue(Charset.forName(String.valueOf(value)));
		}
	}

	@Override
	public String converter() {
		if(getValue()==null) {
			return null;
		}
		Charset value = (Charset) getValue();
		return (value != null ? value.name() : "");
	}
	
}
